package top.zhangjianyong.tools.reptile;

import top.zhangjianyong.tools.utils.JDBCUtil;

import java.io.File;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.sql.SQLException;

/**
 * @author ： zhangjianyong
 * @date ： 2023/3/24 3:23 PM
 */
public class ReptileClear {
    public static void main(String[] args) throws SQLException, IOException {
        JDBCUtil.init();
        JDBCUtil.update("truncate table reptile_img");
        JDBCUtil.update("truncate table reptile_url");
        JDBCUtil.close();
        String path = "/Users/zhangjianyong/img";

        Files.walkFileTree(Paths.get(path), new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.delete(file);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                Files.delete(dir);
                return FileVisitResult.CONTINUE;
            }
        });
    }
}
